#include "pch.h"
#include "include/forward.h"
#include "include/baselink.h"
#include <unordered_map>

typedef std::unordered_map<UINT32, BaseLink*>	CForwardProtocolMap;
typedef std::unordered_map<UINT32, std::pair<BaseLink*, BaseLink*> >	CForwardRpcMap;
//-------------------------------------------------------------------------------------
CForwardProtocolMap forwardProtocolMap;
CForwardRpcMap forwardRpcMap;

void ProtocolForward::RegistForward(UINT32 dwType, BaseLink* link)
{
	forwardProtocolMap[dwType] = link;
}

BaseLink* ProtocolForward::GetProtocolForwardLink(UINT32 dwType)
{
	CForwardProtocolMap::iterator it = forwardProtocolMap.find(dwType);
	if (it != forwardProtocolMap.end())
	{
		return it->second;
	}
	return NULL;
}

void RpcForward::RegistForward(UINT32 dwType, BaseLink* reqForwardLink, BaseLink* rplForwardLink)
{
	forwardRpcMap[dwType] = std::make_pair(reqForwardLink, rplForwardLink);
}

BaseLink* RpcForward::GetRpcForwardLink(UINT32 dwType, bool isRequest)
{
	CForwardRpcMap::iterator it = forwardRpcMap.find(dwType);
	if (it != forwardRpcMap.end())
	{
		return isRequest?it->second.first: it->second.second;
	}
	return NULL;
}
